package com.generator.purchaseManage.manufacturerManage.service.impl;

import com.generator.statics.manufacturerPurchaseStatics.pojo.City1;
import com.generator.statics.manufacturerPurchaseStatics.pojo.Province1;
import com.generator.purchaseManage.manufacturerManage.dao.manufacturerManageDao;
import com.generator.purchaseManage.manufacturerManage.pojo.*;
import com.generator.purchaseManage.manufacturerManage.service.manufacturerManageService;
import com.generator.util.PageModel;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class manufacturerManageServiceImpl implements manufacturerManageService {

    @Autowired
    private manufacturerManageDao manufacturerManageDaoFun;

    public manufacturerManageDao getManufacturerManageDaoFun() {
        return manufacturerManageDaoFun;
    }

    public void setManufacturerManageDaoFun(manufacturerManageDao manufacturerManageDaoFun) {
        this.manufacturerManageDaoFun = manufacturerManageDaoFun;
    }

    // 查询所有厂商管理信息
    @Override
    public List<CFirmManuConn> getAllManuManagement(CFirmManu purchase) {
        return manufacturerManageDaoFun.getAllManuManagement(purchase);
    }

    // 查询所有厂商管理信息(分页)
    @Override
    public PageModel<CFirmManuConn> getAllManuManagement(CFirmManu purchase, PageModel<CFirmManuConn> pageModel) {
        pageModel.setPageNum(pageModel.getPageNum() <= 0 ? 1 : pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize() <= 0 ? 10 : pageModel.getPageSize());

        PageHelper.startPage(pageModel.getPageNum(), pageModel.getPageSize());

        List<CFirmManuConn> list = manufacturerManageDaoFun.getAllManuManagement(purchase);

        PageInfo<CFirmManuConn> pageInfo = new PageInfo<CFirmManuConn>(list);

        pageModel.setData(new ArrayList<CFirmManuConn>(list));
        pageModel.setTotalPage(pageInfo.getPages());
        pageModel.setTotalRows(pageInfo.getTotal());

        return pageModel;
    }

    // 查询单个厂商管理信息
    @Override
    public CFirmManuConn getOneManuManagement(CFirmManuConn conn) {
        return manufacturerManageDaoFun.getOneManuManagement(conn);
    }

    // 修改单个厂商管理信息
    @Override
    public int updateManuManagement(CFirmManuConn user) {
        return manufacturerManageDaoFun.updateManuManagement(user);
    }

    @Override
    public int deleteManuManagement(String ids) {
        return manufacturerManageDaoFun.deleteManuManagement(ids);
    }


    @Override
    public String queryProvince(Province1 province) {
        return manufacturerManageDaoFun.queryProvince(province);
    }

    @Override
    public String queryCity(City1 city1) {
        return manufacturerManageDaoFun.queryCity(city1);
    }

    @Override
    public int addManuManagement(CFirmManuConn conn) {
        return manufacturerManageDaoFun.addManuManagement(conn);
    }

    @Override
    public List<CFirmManuConn> vagueManufacturerSelect(CFirmManuConn conn) {
        return manufacturerManageDaoFun.vagueManufacturerSelect(conn);
    }

    @Override
    public PageModel<CFirmManuConn> vagueManufacturerSelect(CFirmManuConn conn, PageModel<CFirmManuConn> pageModel) {
        pageModel.setPageNum(pageModel.getPageNum() <= 0 ? 1 : pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize() <= 0 ? 10 : pageModel.getPageSize());

        PageHelper.startPage(pageModel.getPageNum(), pageModel.getPageSize());

        List<CFirmManuConn> list = manufacturerManageDaoFun.vagueManufacturerSelect(conn);

        PageInfo<CFirmManuConn> pageInfo = new PageInfo<CFirmManuConn>(list);

        pageModel.setData(new ArrayList<CFirmManuConn>(list));
        pageModel.setTotalPage(pageInfo.getPages());
        pageModel.setTotalRows(pageInfo.getTotal());

        return pageModel;
    }


}
